import { DefendSkillPropListPanel } from "../defend/DefendSkillPropListPanel";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { SkillConfig } from "../../../resource/SkillConfig";
import { SkillInfo } from "../../../model/SkillInfo";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { ShortcutsItem } from "../../shortcuts/ShortcutsItem";
import { MsgManager } from "../../../manager/MsgManager";
import { Language } from "../../../../../extend/language/Language";
import { GameMapUtil } from "../../../scene/map/GameMapUtil";
import { RolePlayer } from "../../../scene/player/entity/RolePlayer";
import { SDefenseUseSkill } from "../../../../../Message/Public/SDefenseUseSkill";
import { SPoint } from "../../../../../Message/Public/SPoint";
import { ThingUtil } from "../../../scene/layer/utils/ThingUtil";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { SCopyEightyDefenceInfo } from "../../../../../Message/Public/SCopyEightyDefenceInfo";
import { CDItemData } from "../../../cache/CDItem/CDItemData";
import { SceneRange } from "../../../scene/map/SceneRange";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
type int = number;
//class EightyDefenceSkillPanel
    
    export  class EightyDefenceSkillPanel extends DefendSkillPropListPanel
    {
        constructor(arg1: int=5, arg2: Boolean=false, arg3: string="", arg4: string="", arg5: Boolean=false)
        {
            super(arg1, arg2, arg3, arg4, arg5);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this._valueTxt = ObjCreate.createTextField("", 0, -20, this.width, 30, this, GlobalStyle.getTextFormatCenter(GlobalStyle.textFormat6));
            return;
        }

        public updateSkillInfos(arg1: Map<any, any> /* flash.utils.Dictionary */): void
        {
            var loc3=null;
            var loc4=0;
            if (arg1 == null) 
            {
                return;
            }
            this._infos = arg1;
            var loc1=[];
            var loc2=[];
            var loc5=0;
            var loc6=arg1;
            for(loc3 of loc6) 
            {
                if (!loc3) 
                {
                    continue;
                }
                loc1.push(loc3);
            }
            loc1.sortOn("id", Array.NUMERIC);
            loc4 = 0;
            while (loc4 < loc1.length) 
            {
                loc3 = loc1[loc4];
                loc2.push(loc3.skillId);
                ++loc4;
            }
            this.setPropListData(loc2);
            return;
        }

        public /* override */ setPropListData(arg1: Array<any>): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            while (loc3 < _skillMaxNum) 
            {
                if (loc3 < arg1.length) 
                {
                    loc1 = SkillConfig.instance.getInfoByName(arg1[loc3]);
                    loc2 = new SkillInfo();
                    loc2.tSkill = loc1;
                    loc2.learned = true;
                    loc2.position = loc3 + 1;
                    _propVec[loc3].dragSource = loc2;
                    _propVec[loc3].filters = [FilterConst.colorFilter];
                }
                else 
                {
                    _propVec[loc3].dragSource = null;
                }
                ++loc3;
            }
            return;
        }

        protected /* override */ onItemClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc1=arg1.target as ShortcutsItem;
            if (loc1.playingEffect) 
            {
                MsgManager.showRollTipsMsg(Language.getString(60054));
            }
            else if (loc1.dragSource) 
            {
                loc3 = loc1.dragSource as SkillInfo;
                loc4 = this._infos[loc3.skillId];
                loc5 = GameMapUtil.getTilePoint(RolePlayer.instance.x, RolePlayer.instance.y);
                loc2 = new SDefenseUseSkill();
                loc2.skillId = loc3.skillId;
                loc2.mousePoint = new SPoint();
                if (ThingUtil.selectEntity != null) 
                {
                    loc2.entityIds = [ThingUtil.selectEntity.entityInfo.entityInfo.entityId];
                }
                if (loc5 != null) 
                {
                    loc2.mousePoint.x = loc5.x;
                    loc2.mousePoint.y = loc5.y;
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.EightyDefenseCopyUseSkill, loc2));
            }
            return;
        }

        public updateSkillCd(arg1: SCopyEightyDefenceInfo): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            if (arg1 == null) 
            {
                return;
            }
            this._valueTxt.htmlText = "<font color=\'#f0ea3f\'>" + Language.getString(90323) + arg1.score + "</font>";
            this._defenceInfo = arg1;
            var loc4=0;
            while (loc4 < _propVec.length) 
            {
                if ((loc3 = _propVec[loc4] as ShortcutsItem) && loc3.dragSource) 
                {
                    loc1 = loc3.dragSource as SkillInfo;
                    if (loc1) 
                    {
                        loc2 = this._infos[loc1.skillId];
                    }
                    if (loc2 && arg1.score < loc2.useScore) 
                    {
                        loc3.filters = [FilterConst.colorFilter];
                    }
                    else 
                    {
                        loc3.enabled = true;
                        loc3.filters = [];
                    }
                }
                ++loc4;
            }
            if (arg1.skillUpdate) 
            {
                this.startSkillCd();
            }
            return;
        }

        /* internal  */startSkillCd(): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc5=null;
            if (this._defenceInfo == null) 
            {
                return;
            }
            var loc4=this._defenceInfo.skillCd;
            var loc6=this._defenceInfo.nowDt;
            var loc7=0;
            while (loc7 < _propVec.length) 
            {
                loc3 = _propVec[loc7] as ShortcutsItem;
                if (loc3 && loc3.dragSource) 
                {
                    loc1 = new CDItemData();
                    loc1.totalTime = 1000;
                    loc2 = loc3.dragSource as SkillInfo;
                    if (loc2) 
                    {
                        if ((loc5 = loc4[loc2.skillId]) && loc5.time > loc6.time) 
                        {
                            loc1.totalTime = loc5.time - loc6.time;
                        }
                    }
                    loc3.doCoolDown(loc1, true);
                }
                ++loc7;
            }
            return;
        }

        public stageResize(): void
        {
            this.x = SceneRange.display.width - 550;
            this.y = SceneRange.display.height - 110;
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            super.show(arg1, arg2);
            this.stageResize();
            return;
        }

        /* internal */ /* var */_infos: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_valueTxt: GTextFiled;

        /* internal */ /* var */_defenceInfo: SCopyEightyDefenceInfo;
    }
